﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
namespace zjbks
{
    public partial class SheZhiFenShuXian : System.Web.UI.Page
    {
        
        protected void Page_Load(object sender, EventArgs e)
        {
            GridView1.DataBind();
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            // 指定保存位置
            string savepath = System.Web.HttpContext.Current.Server.MapPath("./files/");
            if (FileUpload1.HasFile)
            {
                string filename = FileUpload1.FileName;
                savepath += filename;
                FileUpload1.SaveAs(savepath);
                try
                {
                    ExcelToMSSql.DataTranfsub(savepath);
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('成功');</script>");
                    GridView1.DataBind();
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('"+ex+"');</script>");
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('失败');</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择文件')</script>");
            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            // 指定保存位置
            string savepath = System.Web.HttpContext.Current.Server.MapPath("./files/");
            if (FileUpload1.HasFile)
            {
                string filename = FileUpload1.FileName;
                savepath += filename;
                FileUpload1.SaveAs(savepath);
                try
                {
                    ExcelToMSSql.DataTranfKC(savepath);
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('成功');</script>");
                    GridView2.DataBind();
                }
                catch (Exception ex)
                {
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + ex + "');</script>");
                    ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('失败');</script>");
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择文件')</script>");
            }
        }
    }
}